#include "indicatelineitem.h"
#include <QPainter>

IndicateLineItem::IndicateLineItem():
    m_brun(true)
{
    m_pixmap = new QImage(640,360,QImage::Format_ARGB32);
    m_pixmap->fill(0);

    m_ptimage.load(":/image/point.png","png");
    m_timer.setInterval(200);
    connect(&m_timer,SIGNAL(timeout()),this,SLOT(Logic()));
}

void IndicateLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    painter->drawPixmap(QRectF(0.0,0.0,640.0,360.0),
                        QPixmap::fromImage(*m_pixmap),
                        QRectF(0.0,0.0,640.0,360.0));
}

QRectF IndicateLineItem::boundingRect() const
{
    return QRectF(0.0,0.0,640.0,360.0);
}

void IndicateLineItem::Logic()
{
    if(m_brun)
    {
        m_pixmap->fill(0);
        QPainter p(m_pixmap);
        if(m_iPtNum < m_ptarr.count())
        {
            for(int i = 0; i < m_iPtNum;++i)
            {
                p.drawImage(QRectF(m_ptarr[i],QSize(14,14)),m_ptimage,
                            QRectF(0.0,0.0,14.0,14.0));
            }
            ++m_iPtNum;
        }
        else
        {
            m_iPtNum = 0;
        }
        update();
    }
}
